package com.zhu.work;

import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;

public class VfsMain {
    public static void main(String[] args) throws MalformedURLException {
        byte[] bb = new byte[1024];
        URL.setURLStreamHandlerFactory(new YmsURLStreamHandlerFactory());
        URL res = Thread.currentThread().getContextClassLoader().getResource("test.zhu");
        URL testraw = new URL("yms", null, -1, res.getFile(), null);
        try (InputStream is = testraw.openStream();
             ByteArrayOutputStream os = new ByteArrayOutputStream();
             BufferedInputStream bis = new BufferedInputStream(is);
             BufferedOutputStream bos = new BufferedOutputStream(os);) {

            int n = -1;
            while ((n = bis.read(bb)) != -1) {
                bos.write(bb, 0, n);
            }
            bos.flush();
            System.out.println(new String (os.toByteArray()));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
